home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_08
/
ramey.exe
/
PSORT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-14
|
2KB
|
69 lines
char *cmsg = "Postman's Sort (R) Version 1.0\n\
Copyright (c) Robert Ramey 1991. All Rights Reserved\n";
#include <stdio.h>
#include "psort.h"
/*********************************************************************
main program - entry point
**********************************************************************/
main(argc, argv)
int argc;
char *argv[];
{
fputs(cmsg, stderr);
/* analize command line */
psort_init(argc, argv);
chkcmd(argc, argv);
sort();
exit(0);
}
char *umsg =
"sort [-t <working dir>] [-s <record size>] [<sort field>...]\n\
sort field := [<sort key>] [-f <field range>]... [-c <character range>]...\n\
sort key := -k <collating sequence> [-i] [-n]\n\
range := <start>[-<end>]\n\
collating sequence := <range> ...\n\
\t|-r <collating sequence>\n";
/*********************************************************************
chkcmd - check that there are no un recognized command line switches
**********************************************************************/
chkcmd(argc, argv)
int argc;
char *argv[];
{
int i, j, k;
j = 0;
for(i = 1;i < argc;++i)
if(argv[i][0] != NULL)
++j;
if(j == 0)
return;
i = 0;
k = j;
while(j > 0){
do{
++i;
}while(argv[i][0] == NULL);
--j;
switch(j){
default:
fprintf(stderr, "%s, ", argv[i]);
break;
case 1:
fprintf(stderr, "%s and ", argv[i]);
break;
case 0:
if(k > 1)
fprintf(stderr, "%s are invalid arguments\n\n", argv[i]);
else
fprintf(stderr, "%s is an invalid argument\n\n", argv[i]);
break;
}
}
error(umsg);
}